package cc.prayol.permission.mapper.auth;

import static cc.prayol.permission.mapper.auth.MenuDynamicSqlSupport.*;
import static org.mybatis.dynamic.sql.SqlBuilder.*;

import cc.prayol.permission.entity.auth.Menu;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.delete.render.DeleteStatementProvider;
import org.mybatis.dynamic.sql.insert.render.InsertStatementProvider;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.update.render.UpdateStatementProvider;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

@Mapper
public interface MenuMapper {
    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    BasicColumn[] selectList = BasicColumn.columnList(menuId, menuName, parentId, orderNum, url, target, menuType, visible, perms, icon, createBy, createTime, updateBy, updateTime, remark);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    long count(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    @DeleteProvider(type=SqlProviderAdapter.class, method="delete")
    int delete(DeleteStatementProvider deleteStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    @InsertProvider(type=SqlProviderAdapter.class, method="insert")
    int insert(InsertStatementProvider<Menu> insertStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @ResultMap("MenuResult")
    Optional<Menu> selectOne(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    @SelectProvider(type=SqlProviderAdapter.class, method="select")
    @Results(id="MenuResult", value = {
        @Result(column="menu_id", property="menuId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="menu_name", property="menuName", jdbcType=JdbcType.VARCHAR),
        @Result(column="parent_id", property="parentId", jdbcType=JdbcType.BIGINT),
        @Result(column="order_num", property="orderNum", jdbcType=JdbcType.INTEGER),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="target", property="target", jdbcType=JdbcType.VARCHAR),
        @Result(column="menu_type", property="menuType", jdbcType=JdbcType.CHAR),
        @Result(column="visible", property="visible", jdbcType=JdbcType.CHAR),
        @Result(column="perms", property="perms", jdbcType=JdbcType.VARCHAR),
        @Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_by", property="createBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="update_by", property="updateBy", jdbcType=JdbcType.VARCHAR),
        @Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR)
    })
    List<Menu> selectMany(SelectStatementProvider selectStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    @UpdateProvider(type=SqlProviderAdapter.class, method="update")
    int update(UpdateStatementProvider updateStatement);

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    default long count(CountDSLCompleter completer) {
        return MyBatis3Utils.countFrom(this::count, menu, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    default int delete(DeleteDSLCompleter completer) {
        return MyBatis3Utils.deleteFrom(this::delete, menu, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    default int deleteByPrimaryKey(Long menuId_) {
        return delete(c -> 
            c.where(menuId, isEqualTo(menuId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    default int insert(Menu record) {
        return MyBatis3Utils.insert(this::insert, record, menu, c ->
            c.map(menuId).toProperty("menuId")
            .map(menuName).toProperty("menuName")
            .map(parentId).toProperty("parentId")
            .map(orderNum).toProperty("orderNum")
            .map(url).toProperty("url")
            .map(target).toProperty("target")
            .map(menuType).toProperty("menuType")
            .map(visible).toProperty("visible")
            .map(perms).toProperty("perms")
            .map(icon).toProperty("icon")
            .map(createBy).toProperty("createBy")
            .map(createTime).toProperty("createTime")
            .map(updateBy).toProperty("updateBy")
            .map(updateTime).toProperty("updateTime")
            .map(remark).toProperty("remark")
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.603+08:00", comments="Source Table: sys_menu")
    default int insertSelective(Menu record) {
        return MyBatis3Utils.insert(this::insert, record, menu, c ->
            c.map(menuId).toPropertyWhenPresent("menuId", record::getMenuId)
            .map(menuName).toPropertyWhenPresent("menuName", record::getMenuName)
            .map(parentId).toPropertyWhenPresent("parentId", record::getParentId)
            .map(orderNum).toPropertyWhenPresent("orderNum", record::getOrderNum)
            .map(url).toPropertyWhenPresent("url", record::getUrl)
            .map(target).toPropertyWhenPresent("target", record::getTarget)
            .map(menuType).toPropertyWhenPresent("menuType", record::getMenuType)
            .map(visible).toPropertyWhenPresent("visible", record::getVisible)
            .map(perms).toPropertyWhenPresent("perms", record::getPerms)
            .map(icon).toPropertyWhenPresent("icon", record::getIcon)
            .map(createBy).toPropertyWhenPresent("createBy", record::getCreateBy)
            .map(createTime).toPropertyWhenPresent("createTime", record::getCreateTime)
            .map(updateBy).toPropertyWhenPresent("updateBy", record::getUpdateBy)
            .map(updateTime).toPropertyWhenPresent("updateTime", record::getUpdateTime)
            .map(remark).toPropertyWhenPresent("remark", record::getRemark)
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default Optional<Menu> selectOne(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectOne(this::selectOne, selectList, menu, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default List<Menu> select(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectList(this::selectMany, selectList, menu, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default List<Menu> selectDistinct(SelectDSLCompleter completer) {
        return MyBatis3Utils.selectDistinct(this::selectMany, selectList, menu, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default Optional<Menu> selectByPrimaryKey(Long menuId_) {
        return selectOne(c ->
            c.where(menuId, isEqualTo(menuId_))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default int update(UpdateDSLCompleter completer) {
        return MyBatis3Utils.update(this::update, menu, completer);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    static UpdateDSL<UpdateModel> updateAllColumns(Menu record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(menuId).equalTo(record::getMenuId)
                .set(menuName).equalTo(record::getMenuName)
                .set(parentId).equalTo(record::getParentId)
                .set(orderNum).equalTo(record::getOrderNum)
                .set(url).equalTo(record::getUrl)
                .set(target).equalTo(record::getTarget)
                .set(menuType).equalTo(record::getMenuType)
                .set(visible).equalTo(record::getVisible)
                .set(perms).equalTo(record::getPerms)
                .set(icon).equalTo(record::getIcon)
                .set(createBy).equalTo(record::getCreateBy)
                .set(createTime).equalTo(record::getCreateTime)
                .set(updateBy).equalTo(record::getUpdateBy)
                .set(updateTime).equalTo(record::getUpdateTime)
                .set(remark).equalTo(record::getRemark);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    static UpdateDSL<UpdateModel> updateSelectiveColumns(Menu record, UpdateDSL<UpdateModel> dsl) {
        return dsl.set(menuId).equalToWhenPresent(record::getMenuId)
                .set(menuName).equalToWhenPresent(record::getMenuName)
                .set(parentId).equalToWhenPresent(record::getParentId)
                .set(orderNum).equalToWhenPresent(record::getOrderNum)
                .set(url).equalToWhenPresent(record::getUrl)
                .set(target).equalToWhenPresent(record::getTarget)
                .set(menuType).equalToWhenPresent(record::getMenuType)
                .set(visible).equalToWhenPresent(record::getVisible)
                .set(perms).equalToWhenPresent(record::getPerms)
                .set(icon).equalToWhenPresent(record::getIcon)
                .set(createBy).equalToWhenPresent(record::getCreateBy)
                .set(createTime).equalToWhenPresent(record::getCreateTime)
                .set(updateBy).equalToWhenPresent(record::getUpdateBy)
                .set(updateTime).equalToWhenPresent(record::getUpdateTime)
                .set(remark).equalToWhenPresent(record::getRemark);
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default int updateByPrimaryKey(Menu record) {
        return update(c ->
            c.set(menuName).equalTo(record::getMenuName)
            .set(parentId).equalTo(record::getParentId)
            .set(orderNum).equalTo(record::getOrderNum)
            .set(url).equalTo(record::getUrl)
            .set(target).equalTo(record::getTarget)
            .set(menuType).equalTo(record::getMenuType)
            .set(visible).equalTo(record::getVisible)
            .set(perms).equalTo(record::getPerms)
            .set(icon).equalTo(record::getIcon)
            .set(createBy).equalTo(record::getCreateBy)
            .set(createTime).equalTo(record::getCreateTime)
            .set(updateBy).equalTo(record::getUpdateBy)
            .set(updateTime).equalTo(record::getUpdateTime)
            .set(remark).equalTo(record::getRemark)
            .where(menuId, isEqualTo(record::getMenuId))
        );
    }

    @Generated(value="org.mybatis.generator.api.MyBatisGenerator", date="2020-09-07T20:11:24.604+08:00", comments="Source Table: sys_menu")
    default int updateByPrimaryKeySelective(Menu record) {
        return update(c ->
            c.set(menuName).equalToWhenPresent(record::getMenuName)
            .set(parentId).equalToWhenPresent(record::getParentId)
            .set(orderNum).equalToWhenPresent(record::getOrderNum)
            .set(url).equalToWhenPresent(record::getUrl)
            .set(target).equalToWhenPresent(record::getTarget)
            .set(menuType).equalToWhenPresent(record::getMenuType)
            .set(visible).equalToWhenPresent(record::getVisible)
            .set(perms).equalToWhenPresent(record::getPerms)
            .set(icon).equalToWhenPresent(record::getIcon)
            .set(createBy).equalToWhenPresent(record::getCreateBy)
            .set(createTime).equalToWhenPresent(record::getCreateTime)
            .set(updateBy).equalToWhenPresent(record::getUpdateBy)
            .set(updateTime).equalToWhenPresent(record::getUpdateTime)
            .set(remark).equalToWhenPresent(record::getRemark)
            .where(menuId, isEqualTo(record::getMenuId))
        );
    }
}